﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using DjangoRESTFrameworkDAL.Model.DjangoRESTFrame;
using Newtonsoft.Json;

namespace DjangoRESTFrameworkDAL.REST
{
    public interface IOptions
    {
        string Url { get; }
    }


    public static class OptionsEx
    {
        /// <summary>
        ///     获取详细内容
        /// </summary>
        /// <typeparam name="T">序列化数据模型类型</typeparam>
        /// <param name="dal">DAL实例化对象</param>
        /// <returns>返回实例对象</returns>
        public static async Task<OptionsModel> OptionsAsync<T>(this T dal) where T : IOptions
        {
            var request = new HttpRequestMessage(HttpMethod.Options, dal.Url);
            var response = await RestHttpClient.Instance.SendAsync(request);
            var responseBody = await response.Content.ReadAsStringAsync();
            return JsonConvert.DeserializeObject<OptionsModel>(responseBody);
        }
    }
}
